
import Vue from 'vue'
import App from './App'
import Mint from 'mint-ui';
import 'mint-ui/lib/style.css'
import VuePreview from 'vue2-preview'
Vue.use(VuePreview)
Vue.use(Mint);
import router from './router'
Vue.config.productionTip = false;

Vue.http.get('../static/config.json').then(function (result) {
  var APP_ID = result.body.appId;
  var APP_KEY = result.body.appKey;
  AV.init({
    appId: APP_ID,
    appKey: APP_KEY
  });
  checkoutUser()
})

function checkoutUser() {
  router.beforeEach((to, from, next) => {
     // next()
    var currentUser = AV.User.current();
    if (to.path === '/') {
      next()
    } else {
      if (currentUser) {
        Vue.prototype.currentUser = currentUser.toJSON().username
        next()
      }
      else {
        next({path: '/'})
      }
    }
  });
  init();
}
function init() {
  new Vue({
    el: '#app',
    router,
    components: { App },
    template: '<App/>'
  });
}


